/**
  ******************************************************************************
  * @file    SRAM_Driver.h
  * @author  tuancheng_Zero
  * @version V0.1
  * @date    08/05/2024
  * @brief   extern Sram Drive
  ******************************************************************************
*/ 
#ifndef  __SRAM_DRIVER_H__
#define  __SRAM_DRIVER_H__
#ifdef __cplusplus
extern "C" {
#endif

/**
  * @brief GLOBALS RAM definition
  */
#ifdef   EEPROM_GLOBALS
#define  SRAM_DRIVER_EXT
#else
#define  SRAM_DRIVER_EXT  extern
#endif

//全局宏定义
#define SRAM_DMA_BUFF_SIZE        1028   // dma缓冲区大小
#define SRAMCMD_READ              0x03   /* 0000 0011 Read Data from Memory    */
#define SRAMCMD_WRITE             0x02   /* 0000 0010 Write Data to Memory     */

//gpio配置
#define SRAM_GPIOx                 GPIOE
#define SRAM_GPIO_RCC_Periph       RCC_APB2_PERIPH_GPIOE    
#define SRAM_GPIO_Mode_MOSI        GPIO_Mode_AF_PP          
#define SRAM_GPIO_Pin_MOSI         GPIO_PIN_9
#define SRAM_GPIO_Mode_MISO        GPIO_Mode_IPU     
#define SRAM_GPIO_Pin_MISO         GPIO_PIN_8
#define SRAM_GPIO_Mode_SCK         GPIO_Mode_AF_PP           
#define SRAM_GPIO_Pin_SCK          GPIO_PIN_7
#define SRAM_GPIO_Mode_CS          GPIO_Mode_Out_PP   
#define SRAM_GPIO_Pin_CS           GPIO_PIN_10

//spi配置
#define SRAM_SPI                   SPI1
#define SRAM_Direction             SPI_DIR_DOUBLELINE_FULLDUPLEX
#define SRAM_Mode                  SPI_MODE_MASTER
#define SRAM_DataSize              SPI_DATA_SIZE_8BITS
#define SRAM_CPOL                  SPI_CLKPOL_HIGH
#define SRAM_CPHA                  SPI_CLKPHA_SECOND_EDGE
#define SRAM_NSS                   SPI_NSS_SOFT
#define SRAM_BaudRatePres          SPI_BR_PRESCALER_32
#define SRAM_FirstBit              SPI_FB_MSB
#define SRAM_CRCPoly               7

//DMA配置
#define SRAM_DMA_RCC_Periph        RCC_AHBPeriph_DMA1 
#define SRAM_DR_Address            ((uint32_t)&SPI1->DAT)
#define SRAM_DMA_Rx_IRQn           DMA1_Channel2_IRQn
#define SRAM_DMA_Tx_Channel        DMA1_CH3
#define SRAM_DMA_Rx_Channel        DMA1_CH2
#define SRAM_DMA_Rx_FLAG           (DMA1_FLAG_GL2|DMA1_FLAG_TC2|DMA1_FLAG_TE2|DMA1_FLAG_HT2)  
#define SRAM_DMA_Rx_Function       DMA1_Channel2_IRQHandler

SRAM_DRIVER_EXT void SRAM_Init(void);
SRAM_DRIVER_EXT uint8_t SRAM_WriteData(uint32_t addr, uint8_t * writeData, uint16_t length);
SRAM_DRIVER_EXT uint8_t SRAM_ReadData(uint32_t addr, uint8_t * readData, uint16_t length);

#ifdef __cplusplus
}
#endif
#endif   /*   __EXTEND_SRAM_H__   */
